﻿@using EasyAbp.IdentityServerAdmin.ApiResources.Dtos
@using IdentityServer4.Models
<Validations Model="ApiSecretList">
    <Card>
        <CardBody>
            @foreach(var apiSecret in ApiSecretList){
                <Card Class="mb-2">
                    <CardBody>
                       <Validation>
                            <Field>
                                <FieldLabel>Secret Type</FieldLabel>
                                <FieldBody>
                                      <Select @bind-SelectedValue="apiSecret.Type">
                                        <SelectItem Value="@("SharedSecret")">Shared Secret</SelectItem>
                                    </Select>
                                </FieldBody>
                            </Field>
                       </Validation>
                       <Validation>
                           <Field>
                               <FieldLabel>Secret Value</FieldLabel>
                               <FieldBody>
                                   <TextEdit @bind-Text="apiSecret.Value"
                                             @onchange="@(()=>{
                                             apiSecret.Value = apiSecret.Value.Sha256();
                                            })"></TextEdit>
                               </FieldBody>
                               <FieldHelp>
                                     Attension:Input value will encode with sha256.
                               </FieldHelp>
                           </Field>
                       </Validation>
                       <Validation>
                           <Field>
                               <FieldLabel>Description</FieldLabel>
                               <FieldBody>
                                     <TextEdit @bind-Text="apiSecret.Description"></TextEdit>
                               </FieldBody>
                           </Field>
                       </Validation>
                       <Validation>
                           <Field>
                               <FieldLabel>Expiration</FieldLabel>
                               <FieldBody>
                                   <DateEdit @bind-Date="apiSecret.Expiration"></DateEdit>
                               </FieldBody>
                           </Field>
                       </Validation>
                    </CardBody>
                    <CardFooter>
                        <Button
                                Color="Color.Danger"
                                Clicked="()=>{
                                    ApiSecretList.Remove(apiSecret);
                                    ApiSecretListChanged.InvokeAsync(ApiSecretList);
                                }"
                                >Delete</Button>
                    </CardFooter>
                </Card>
            }
        </CardBody>
        <CardFooter>
            <Button Color="Color.Primary"

                    Clicked="()=>{
                        ApiSecretList.Add(new ApiSecretDto());
                        ApiSecretListChanged.InvokeAsync(ApiSecretList);
                    }"
                >New Secret</Button>
        </CardFooter>
    </Card>
</Validations>







@code {
    [Parameter]
    public List<ApiSecretDto> ApiSecretList { get; set; } = new List<ApiSecretDto>();

    [Parameter]
    public EventCallback<List<ApiSecretDto>> ApiSecretListChanged { get; set; }
}
